package com.sdkx.app.activitys;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.RelativeLayout;

import com.sdkx.app.R;

import org.litepal.LitePal;

public class SplashActivity extends Activity {
    private RelativeLayout rl_splash_bg;
    protected static final int COPY_DB_ERROR = 17;
    protected static final int COPY_DB_SUCCESS = 18;
    protected static final int COPY_DB_EXIT = 19;
    // 定义一个消息处理器 在主线程里面创建
    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case COPY_DB_SUCCESS:
                    
                    loadMainUI();
                    break;
                case COPY_DB_ERROR:
                    
                    loadMainUI();
                case COPY_DB_EXIT:
                    loadMainUI();
                    break;
            }
        }
    };

    /**
     * 进入主界面.
     */
    public void loadMainUI() {
        
//        WayPoint.getAllMCustomWP(getApplicationContext());
//        MCustomWpDBUtil.getAllMCustomAirP(getApplicationContext());
//        MyApp myapp= (MyApp) getApplication();
//        myapp.idAirPortCaches = MCustomWpDBUtil.idAirPortCaches;
//        myapp.idWayPointCaches = MCustomWpDBUtil.idWayPointCaches;
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        // 把splash界面给关闭掉
        this.finish();
    }


    @Override
    protected void onCreate( Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);//没有标题
        super.onCreate(savedInstanceState);
        //网络上找到的防止返回
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
            }
        //
        setContentView(R.layout.activity_splash);
        rl_splash_bg=(RelativeLayout)findViewById(R.id.rl_splash_bg);
        AlphaAnimation aa = new AlphaAnimation(0.2f, 1.0f);
        aa.setDuration(500);
        aa.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Message msg = Message.obtain();
                msg.what = COPY_DB_SUCCESS;
                handler.sendMessage(msg);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        rl_splash_bg.startAnimation(aa);
    }

}
